package com.haochen.gateway.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @Author: zhangquancheng
 * @Description:
 */
@RestController
public class OuserController {
    private String serviceName = "ouser-service";
    @Autowired
    private RestTemplate restTemplate;

    @RequestMapping(method = RequestMethod.GET,path = "/getUser")
    @HystrixCommand(fallbackMethod = "getOuserFallBack")
    public String getUserOrder(){
        return restTemplate.getForObject("http://"+serviceName+"/getUser",String.class);
    }

    /**
     * @Description 服务降级方法
     */
    public String getOuserFallBack(){
        return "OUSER 服务烦忙，稍后再试！";
    }
}
